package com.林子祺.全名健康管理系统.view.servlet.login;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

//返回用户层
@WebServlet("/user")
public class User extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        HttpSession session = req.getSession();
        String work = (String) session.getAttribute("work");
        if((String) session.getAttribute("user") != null && work !=null){
            req.setAttribute("state",work);
        }
        else {
            work = "0";
            req.setAttribute("state", "0");
        }

        if(work.equals("3")) {
            req.getRequestDispatcher("/login/admin.jsp").forward(req, resp);
        }
        else {
            req.getRequestDispatcher("/login/user.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
